package com.czy.utilslib;

import io.reactivex.Single;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.android.schedulers.AndroidSchedulers;
public class RxJavaUtils {

    // Single.fromCallable的返回值result是boolean
    public static Disposable launchIO(Runnable block) {
        return Single.fromCallable(() -> {
                    block.run();
                    return true;
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        result -> {
                            if(result){

                            }
                        },
                        throwable -> {

                        }
                );
    }

    public static Disposable launchUI(Runnable block) {
        return Single.fromCallable(() -> {
                    block.run();
                    return true;
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        result -> {

                        },
                        throwable -> {

                        }
                );
    }

}
